package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// TerminalConfig 终端配置
type TerminalConfig struct {
	ID           string `json:"id" gorm:"primaryKey;column:id;type:int;size:64;comment:主键"`
	RobotID      string `json:"robot_id" gorm:"column:robot_id;type:string;size:40;index:idx_key,unique,priority:1;comment:设备id"`
	TerminalType string `json:"terminal_type" gorm:"column:terminal_type;type:string;size:40;index:idx_key,unique,priority:2;comment:终端类型"`
	Key          string `json:"key" gorm:"column:key;type:string;size:40;index:idx_key,unique,priority:3;comment:配置的key"`
	Value        string `json:"value" gorm:"column:value;type:string;size:1024;comment:配置的value"`
	CreatedAt    int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	UpdatedAt    int64  `json:"updated_at" gorm:"autoUpdateTime;column:updated_at;type:int;size:64;comment:更新时间"`
}

// TableName 表名称
func (TerminalConfig) TableName() string {
	return "terminal_config"
}

// BeforeCreate 自增id
func (t *TerminalConfig) BeforeCreate(tx *gorm.DB) (err error) {
	if t.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	t.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &TerminalConfig{})
}
